<?php
	//上传文件的属性
function upload_info($fileinfo,$maxsize=2097152,
					$path="uploads",
					$allowext=array('doc','ppt','xls','wps','txt','jpg','jpeg','png','gif','pdf')
					){
		$filename=$fileinfo['name'];
		$type=$fileinfo['type'];
		$error=$fileinfo['error'];
		$size=$fileinfo['size'];
		$tmp_name=$fileinfo['tmp_name'];
		//判断错误信息,只有为0和UPLOAD_ERR_OK的时候才正确
		if($error==UPLOAD_ERR_OK){
			if($size>$maxsize){
				exit('上传文件大于2m');
			}
			$ext=pathinfo($filename,PATHINFO_EXTENSION);
			if(!in_array($ext,$allowext)){
				exit('非法文件类型');
			}
			// if(!is_uploaded_file($filename)){
			// 	exit('文件不是通过http post上传');
			// }
			$uniName=md5(uniqid(microtime(true),true)).'.'.$ext;
			$destnation=$path.'/'.$uniName;
			if(!is_array($allowext)){
				echo '系统错误';
			}
			if(!file_exists($path)){
				mkdir($path,0777,true);
				chmod($path,0777);
			}
			if(move_uploaded_file($tmp_name,$destnation)){
				echo '文件'.$filename.'上传成功';
			}
			else{
				exit ('文件'.$filename.'上传失败');
			}
		}
		else{
			//错误信息配置
			switch($error) {
				case 1:
					echo '上传文件超过了php配置文件upload_max_filesize选项的值';
					break;
				case 2:
					echo '超过了表单MAX_FILE_SIZE限制的大小';
					break;
				case 3:
				 	echo '文件部分被上传';
				 	break;
				case 4:
					echo '没有选择上传的文件';
					break;
				case 6:
					echo '没有找到临时的目录';
					break;
				case 7:
				case 8:
					echo '系统错误';
					break;
			}
		}
}
	
?>